// 2.给你单链表的头节点 head，请你反转链表，并返回反转后的链表
//     [
//         11 -> 22 -> 33 -> 44
//         44 -> 33 -> 22 -> 11
//     ]

#include <stdio.h>
#include <stdlib.h>

struct ListNode
{
    int val;
    struct ListNode *next;
};

struct ListNode* reversalList(struct ListNode *head)
{
    struct ListNode *prev = NULL;
    struct ListNode *current = head;
    struct ListNode *next;

    while (current != NULL)
    {
        next = current->next;
        current->next = prev;
        prev = current;
        current = next;
    }

    return prev;
}

struct ListNode *creatNode(int val)
{
    struct ListNode *newNode = (struct ListNode*)malloc(sizeof(struct ListNode));
    newNode->val = val;
    newNode->next = NULL;
    return newNode;
}

int main()
{
    struct ListNode *head = creatNode(11);
    head->next = creatNode(22);
    head->next->next = creatNode(33);
    head->next->next->next = creatNode(44);

    struct ListNode *newHead = reversalList(head);
    struct ListNode *current = newHead;
    while (current != NULL)
    {
        printf("%d->", current->val);
        current = current->next;
    }
    printf("NULL\n");

    return 0;
}